#include "log.h"
#include "ui_log.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <QMessageBox>
#include <QTimer>
#include "QLabel"
#include "QMovie"


Log::Log(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Log)
{
    ui->setupUi(this);
    msocket.connectToHost("192.168.19.1",8000);      //默认ip与port

    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(toreg()));
    connect(&msocket,&QTcpSocket::readyRead,this,&Log::read_data);
}

Log::~Log()
{
    delete ui;
}


void Log::read_data()
{
    QString msg;
    msg=msocket.readLine();
    qDebug()<<msg;
    if(msg=="false")
    {
        QMessageBox::information(NULL, "Title", "用户名或密码错误");
    }
    else if(msg=="true")
    {
        QMessageBox::information(NULL, "Title", "登录成功");
        this->close();
    }
    else if(msg=="")
    {
        QMessageBox::information(NULL, "Title", "用户名或密码错误");
    }
}


void Log::toreg()
{
    R.show();
}

void Log::on_pushButton_clicked()
{
    if(ui->checkBox->isChecked())
    {
        QString p1=ui->lineEdit->text();
        QString p2=ui->lineEdit_2->text();
        msocket.write("#");      //#为读取
        msocket.write(p1.toUtf8());
        msocket.write(p2.toUtf8());  //向服务端发送账号密码
        //此处滞后执行
    }
    else
        QMessageBox::information(NULL, "Title", "为什么不勾？阿弥诺斯！");
}


void Log::on_pushButton_2_clicked()  //注册
{

}

